package dom;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Alex
 */
public class HyperAlertType {
	private int id;
	private String name;
	private List<Predicate> prerequisites;
	private List<Predicate> consequences;
	private List<Fact> facts;
	
	public HyperAlertType(){
		prerequisites = new ArrayList<Predicate>();
		consequences = new ArrayList<Predicate>();
		facts = new ArrayList<Fact>();
	}
	
	public HyperAlertType(int id, String name){
		this.id = id;
		this.name = name;
		prerequisites = new ArrayList<Predicate>();
		consequences = new ArrayList<Predicate>();
		facts = new ArrayList<Fact>();
	}
	public HyperAlertType(String name, List<Predicate> prerequisites, List<Predicate> consequences){
		this.name = name;
		this.consequences = consequences;
		this.prerequisites = prerequisites;
	}
	public HyperAlertType(String name, List<Predicate> prerequisites,
			List<Predicate> consequences, List<Fact> facts) {
		this.name = name;
		this.consequences = consequences;
		this.prerequisites = prerequisites;
		this.facts = facts;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Predicate> getPrerequisites() {
		return prerequisites;
	}

	public void setPrerequisites(List<Predicate> prerequisites) {
		this.prerequisites = prerequisites;
	}

	public List<Predicate> getConsequences() {
		return consequences;
	}

	public void setConsequences(List<Predicate> consequences) {
		this.consequences = consequences;
	}
	
	public void addPrerequisite(Predicate p){
		if(prerequisites == null){
			prerequisites = new ArrayList<Predicate>();
		}
		prerequisites.add(p);
	}
	
	public void addConsequence(Predicate p){
		if(consequences == null){
			consequences = new ArrayList<Predicate>();
		}
		consequences.add(p);
	}
	
	public void addFact(Fact f){
		if(facts == null){
			facts = new ArrayList<Fact>();
		}
		facts.add(f);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\n==HyperAlertType=====");
		sb.append("\nName: " + name);
		sb.append("\nID:   " + id);
		sb.append("\n--Facts--------------\n");
		for(Fact f : this.facts){
			sb.append("Name: " + f.getName() + "\n");
		}
		sb.append("--Prequisites--------\n");
		for(Predicate p : this.prerequisites){
			sb.append("Name: " + p.getName() + "\nID:   " + p.getId() + "\n");
		}
		sb.append("--Consequences-------\n");
		for(Predicate c : this.consequences){
			sb.append("Name: " + c.getName() + "\nID:   " + c.getId() + "\n");
		}
		sb.append("====================");
		return sb.toString();
	}

	public List<String> getFacts() {
		List<String> factStrings = new LinkedList<String>();
		for(Fact fact : facts){
			factStrings.add(fact.getName());
		}
		return factStrings;
		
	}
	
	
}
